package cn.edu.hzvtc.haowen.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import cn.edu.hzvtc.haowen.common.utils.uuid.IdUtils;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import cn.edu.hzvtc.haowen.common.annotation.Log;
import cn.edu.hzvtc.haowen.common.core.controller.BaseController;
import cn.edu.hzvtc.haowen.common.core.domain.AjaxResult;
import cn.edu.hzvtc.haowen.common.enums.BusinessType;
import cn.edu.hzvtc.haowen.domain.WenjuanTemplate;
import cn.edu.hzvtc.haowen.service.IWenjuanTemplateService;
import cn.edu.hzvtc.haowen.common.utils.poi.ExcelUtil;
import cn.edu.hzvtc.haowen.common.core.page.TableDataInfo;

/**
 * 问卷模板Controller
 * 
 * @author haowen
 * @date 2024-05-08
 */
@RestController
@RequestMapping("/wenjuan/wenjuan_template")
public class WenjuanTemplateController extends BaseController
{
    @Autowired
    private IWenjuanTemplateService wenjuanTemplateService;

    /**
     * 查询问卷模板列表
     */
    @PreAuthorize("@ss.hasPermi('wenjuan:wenjuan_template:list')")
    @GetMapping("/list")
    public TableDataInfo list(WenjuanTemplate wenjuanTemplate)
    {
        startPage();
        List<WenjuanTemplate> list = wenjuanTemplateService.selectWenjuanTemplateList(wenjuanTemplate);
        return getDataTable(list);
    }

    /**
     * 导出问卷模板列表
     */
    @PreAuthorize("@ss.hasPermi('wenjuan:wenjuan_template:export')")
    @Log(title = "问卷模板", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, WenjuanTemplate wenjuanTemplate)
    {
        List<WenjuanTemplate> list = wenjuanTemplateService.selectWenjuanTemplateList(wenjuanTemplate);
        ExcelUtil<WenjuanTemplate> util = new ExcelUtil<WenjuanTemplate>(WenjuanTemplate.class);
        util.exportExcel(response, list, "问卷模板数据");
    }

    /**
     * 获取问卷模板详细信息
     */
    @PreAuthorize("@ss.hasPermi('wenjuan:wenjuan_template:query')")
    @GetMapping(value = "/{templateId}")
    public AjaxResult getInfo(@PathVariable("templateId") Integer templateId)
    {
        return success(wenjuanTemplateService.selectWenjuanTemplateByTemplateId(templateId));
    }

    /**
     * 新增问卷模板
     */
    @PreAuthorize("@ss.hasPermi('wenjuan:wenjuan_template:add')")
    @Log(title = "问卷模板", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody WenjuanTemplate wenjuanTemplate)
    {
        wenjuanTemplate.setCreateBy(getUsername());
        wenjuanTemplate.setTemplateUuid(IdUtils.simpleUUID());
        return toAjax(wenjuanTemplateService.insertWenjuanTemplate(wenjuanTemplate));
    }

    /**
     * 修改问卷模板
     */
    @PreAuthorize("@ss.hasPermi('wenjuan:wenjuan_template:edit')")
    @Log(title = "问卷模板", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody WenjuanTemplate wenjuanTemplate)
    {
        return toAjax(wenjuanTemplateService.updateWenjuanTemplate(wenjuanTemplate));
    }

    /**
     * 删除问卷模板
     */
    @PreAuthorize("@ss.hasPermi('wenjuan:wenjuan_template:remove')")
    @Log(title = "问卷模板", businessType = BusinessType.DELETE)
	@DeleteMapping("/{templateIds}")
    public AjaxResult remove(@PathVariable Integer[] templateIds)
    {
        return toAjax(wenjuanTemplateService.deleteWenjuanTemplateByTemplateIds(templateIds));
    }
}
